//公共js，主要做表单验证，以及基本方法封装
import Vue from 'vue';
import store from '@/store/index';
import http from './http.js';
// #ifdef H5
import wechat from './wechat.js';
// #endif

let _debounceTimeout = null,
	_throttleRunning = false

let dictInterval = null;

const utils = {
	//useMock: true,
	 useMock: false,
	
	mockData(url, method, param) {
		let data = {
			status: 0
		};
		return data;
	},
	interfaceUrl() {
		// #ifdef H5
		// return `/prod-api/`;
		//#endif
		const url = this.serviceUrl().split('//')[1]
		// if (/^172.30.*$/.test(url)) {
		if (/^192.168.*$/.test(url)) {
			return `${this.serviceUrl()}/`;
		} else {
			// return `${this.serviceUrl()}/prod-api/`;
			return `${this.serviceUrl()}/`;
		}
	},
	fileLoadUrl() {
		return '';
	},
	shareUrl() {
		return `${this.serviceUrl()}/h5/`;
	},
	serviceUrl() {
		//  return 'http://47.104.4.41:9001'
		return 'http://221.176.214.214:32036'
		// #ifdef MP-WEIXIN
		// 小程序后台服务地址
		if (__wxConfig && __wxConfig.envVersion) {
			let version = __wxConfig.envVersion;
			switch (version) {
				case 'develop':
					// 本地开发改这个，下面的不要动
					// return 'http://172.30.247.90:9001';
					// return 'https://newdr.newlifegroup.com.cn';
					// return 'http://192.168.101.82:9001';
					return 'http://221.176.214.214:32036'
					 //return 'http://172.30.247.28:9001';
					break;
				case 'trial':
					// return 'http://114.67.233.142';
					// return 'https://newdr.newlifegroup.com.cn';
					return 'http://192.168.101.82:9001';
					// return 'http://172.30.247.38:9001';
					break;
				default:
					// return 'http://114.67.233.142';
					// return 'https://newdr.newlifegroup.com.cn';
					return 'http://192.168.101.82:9001';
			}
		}
		//#endif

		// #ifdef APP-PLUS
		//APP后台服务地址
		if (process.env.NODE_ENV === 'development') {
			//本地点击运行到...改这个路径，下面的不要动
			// return 'http://114.67.233.142';
			// return 'https://newdr.newlifegroup.com.cn';
			// return 'http://192.168.101.82:9001';
			return 'http://221.176.214.214:32036'
		} else {
			//这个是打包后的路径
			// return 'http://114.67.233.142';
			// return 'https://newdr.newlifegroup.com.cn';
			// return 'http://192.168.101.82:9001';
			return 'http://221.176.214.214:32036'
		}
		//#endif

		// return 'http://114.67.233.142';
		// return 'https://newdr.newlifegroup.com.cn';
		// return 'http://192.168.101.82:9001';
		
	},
	/* ossFileUrl() {
		// #ifdef MP-WEIXIN
		// 小程序后台服务地址
		if (__wxConfig && __wxConfig.envVersion) {
			let version = __wxConfig.envVersion;
			switch (version) {
				case 'develop':
					// 本地开发改这个，下面的不要动
					return 'https://dr-static.oss-cn-shanghai.aliyuncs.com/';
					break;
				case 'trial':
					return 'https://dr-static.oss-cn-shanghai.aliyuncs.com/';
					break;
				default:
					return 'https://dr-static.oss-cn-shanghai.aliyuncs.com/';
			}
		}
		//#endif
	
		// #ifdef APP-PLUS
		//APP后台服务地址
		if (process.env.NODE_ENV === 'development') {
			//本地点击运行到...改这个路径，下面的不要动
			return 'https://dr-static.oss-cn-shanghai.aliyuncs.com/';
		} else {
			//这个是打包后的路径
			return 'https://dr-static.oss-cn-shanghai.aliyuncs.com/';
		}
		//#endif
	
		return 'https://dr-static.oss-cn-shanghai.aliyuncs.com/';
	}, */
	// hideErrorTip 接口可配置boolean值来确认是否隐藏提示
	request(url, method, data, hideLoading, errorType,hideErrorTip=false) {
		// 接口请求
		if (!hideLoading) {
			store.state.showLoading = true;
		}
		
		return new Promise((resolve, reject) => {
			if (!this.useMock) {
				url = url.replace('so-fast-classroom/', '')
				uni.request({
					url: this.interfaceUrl() + url,
					data,
					header: {
						// 'content-type': 'application/json',
						"Authorization": this.getToken() ? this.getToken() : 'Basic YXBwOjAwMDAwMA==',
						"Cookie_lang": "zh_CN",
						"Cookie": "lang=zh_CN",
						'SECURITY_USER_ID':'1381846552136445959'
						// "Accept-Language": "zh_CN",
						// 'token': this.getToken()
						//'Authorization':'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsaWNlbnNlIjoic28tZmFzdCIsInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsicmVhZCIsIndyaXRlIl0sInVzZXJOYW1lIjoiYWRtaW4iLCJ1c2VySWQiOjEsImF1dGhvcml0aWVzIjpbImFkbWluIl0sImp0aSI6IjY3OTQwZjBmLWJkNDQtNGMxNi04MDcwLTU1N2MyNDMzNTNlYyIsImNsaWVudF9pZCI6IndlYiJ9.WezpzCytQ5g3TyeReojX8JV7cHXdh1EIs-DD2a1wmmI'
					},
					method, // 'GET','POST'
					dataType: 'json',
					success: (res) => {
						
						if (!hideLoading) {
							store.state.showLoading = false;
							store.state.loaded = true;
						}
						if (!this.isNullOrEmpty(errorType)) {
							Vue.prototype.$eventHub.$emit(errorType, {
								flg: false,
							});
						}
							if (res.statusCode === 200) {
								if(!hideErrorTip){//接口可配置boolean值来确认是否隐藏提示
									if (res.data.status !== 0) {
										if(url==='so-fast-uaa/login/appleId'){
											// 硬要单独给个判断 不好吧 不好吧 不好吧
											store.state.showErrorModal = true;
											store.state.errorTitle = '';
											store.state.errorText = '首次使用苹果账号登录，请通过微信或账号密码登录并在设置中绑定Apple ID账号';
										}else if (res.data.code != 'Msg.DRMALL.ERR.012') {
											// code Msg.DRMALL.ERR.012表示优惠券领取失败
											store.state.showErrorModal = true;
											store.state.errorTitle = '温馨提醒';
											store.state.errorText = res.data.message;
										}
									}
								}
								resolve(res.data);
							} else {
								if(!hideErrorTip){//接口可配置boolean值来确认是否隐藏提示
									if (res.statusCode === 401) {
										const isReadPolicy = uni.getStorageSync('isReadPolicy');						
										uni.clearStorageSync();
										uni.setStorageSync('isReadPolicy','1');
										// this.wxLogin();
										store.state.showErrorModal = true;
										store.state.errorTitle = '登陆信息失效';
										store.state.errorText = '请重新登录';
										store.state.loginInvalid = true;
									} else if (res.statusCode === 429) {
										store.state.showErrorModal = true;
										store.state.errorTitle = '服务器繁忙';
										store.state.errorText = '当前访问人数太多了，请稍后再试';
									} else if (res.statusCode === 503) {
										store.state.showErrorModal = true;
										store.state.errorTitle = '服务器错误';
										store.state.errorText = '服务器当前不可用，请稍后再试';
									} else {
										store.state.showErrorModal = true;
										store.state.errorTitle = '服务器错误';
										store.state.errorText = '服务器出错了，请稍后再试';
									}
								}else{
									if (res.statusCode === 401) {
										const isReadPolicy = uni.getStorageSync('isReadPolicy');						
										uni.clearStorageSync();
										uni.setStorageSync('isReadPolicy','1');
										// this.wxLogin();
										store.state.loginInvalid = true;
									} 
								}
								reject(res);
							}
					
					},
					fail: (res) => {
						console.log(res)
						if (!hideLoading) {
							store.state.showLoading = false;
						}
						if (!this.isNullOrEmpty(errorType)) {
							Vue.prototype.$eventHub.$emit(errorType, {
								flg: true,
							});
						} else {
							this.toast('网络连接失败，请检查网络设置');
						}
						reject(res);
					},
				});
			} else {
				setTimeout(() => {
					if (!hideLoading) {
						store.state.showLoading = false;
					}
					const resData = this.mockData(url, method, data);
					if (resData.status === 0) {
						resolve(resData);
						console.log(`调用接口:${url}`);
						console.log(`请求方式:${method}`);
					} else {
						if (resData.code != 'Msg.DRMALL.ERR.012') {
							store.state.showErrorModal = true;
							store.state.errorTitle = '温馨提醒';
							store.state.errorText = res.data.message;
						}
						resolve(resData);
					}
				}, 500);
			}
		});
	},
	// 获取用户身份
	getIdentity() {
		http.customerIdentity().then((res) => {
			if (res.status == 0) {
				this.storageIdentity(res);
			}
		})
	},
	//存储用户身份 if (uni.getStorageSync('orgLv') == 'gk'||uni.getStorageSync('orgLv') == 'hy'||uni.getStorageSync('orgLv') == 'dxy'|| this.isHaveMember===0)
	storageIdentity(res) {
		if (res.data.orgLv === 'gk') { // 普通用户
		// if (res.data.orgLv == 'gk'||res.data.orgLv == 'hy'||res.data.orgLv == 'dxy'|| res.data.isHaveMember===0){
			if (store.state.tabbar.length === 5) {
				store.commit('removeFootBar')
			}
		} else { //会员
			if (store.state.tabbar.length === 4) {
				store.commit('changeFootBar', {
					icon: 'iconqianbao2',
					text: "会员钱包"
				})
			}

		}
		store.commit('setOrgLv',res.data.orgLv);
		store.commit('setNickName',res.data.nickName);
		store.commit('setHeadimgurl',res.data.headimgurl);
		uni.setStorageSync('orgLv', res.data.orgLv);
		uni.setStorageSync('orgLvAb', res.data.orgLvAb);
		uni.setStorageSync('shareAgencyId', res.data.shareAgencyId);
		uni.setStorageSync('agencyId', res.data.agencyId);
		uni.setStorageSync('isHaveMember', res.data.isHaveMember);
	},
	// 每15分钟获取字典信息
	getDictDataAll() {
		clearInterval(dictInterval);
		http.dictDataAll({types: 'mengzhu,beautiful_plagued,skin_Type,couponSwitch,couponPacleSwitch,couponType,goodsBrand,points_business_type,agency_point_optType,stopFunction'}).then((res) => {
			if (res.status === 0) {
				store.commit("changeDictDataAll", res.data);
			} else {
				// 取得失败，重新取得
				this.getDictDataAll();
			}
		}).catch(()=>{
			// 取得失败，重新取得
			this.getDictDataAll();
		})
		dictInterval = setInterval(()=>{
			if(this.getToken()) {
				http.dictDataAll({types: 'mengzhu,beautiful_plagued,skin_Type,couponSwitch,couponPacleSwitch,couponType,goodsBrand,points_business_type,agency_point_optType,stopFunction'}).then((res) => {
					if (res.status === 0) {
						store.commit("changeDictDataAll", res.data);
					}
				})
			}
		}, 1000 * 60 * 10);
	},
	// 获取图标设置信息
	getIconSetting() {
		http.getIconSetting().then((res) => {
			if (res.status === 0) {
				console.log(res.data)
				if (res.data && res.data.length > 0) {
					let obj = {};
					res.data.forEach(i => {
						obj[i.iconKey] = i.iconImg ? i.iconImg : '';
					})
					store.commit('setIconSettings', obj);
				}
			}
		})
	},
	// 设置开屏初始化
	setInitSpeadFlag(flag) {
		store.commit('setSpreadInitFlag', flag);
	},
	//过期清除本地缓存
	clearExpiration() {
	  let timestamp = Date.parse(new Date());
	  let data_expiration = uni.getStorageSync('data_expiration');
	  if (data_expiration) {
	    if (timestamp > data_expiration) {
	      const isReadPolicy = uni.getStorageSync('isReadPolicy');
	      uni.clearStorageSync();
	      uni.setStorageSync('isReadPolicy','1');
	    }
	  }
	},
	setExpiration() {
		let timestamp = Date.parse(new Date());
		let expiration = timestamp + 604800000; //有效期7天分钟
		uni.setStorageSync('data_expiration', expiration)
	},
	setToken(token) {
		uni.setStorageSync('token', token ? 'Bearer ' + token : token);
	},
	getToken() {
		return uni.getStorageSync('token');
	},
	setRefreshToken(refreshToken) {
		uni.setStorageSync('refreshToken', refreshToken);
	},
	getRefreshToken() {
		return uni.getStorageSync('refreshToken');
	},
	toast(text, success) {
		uni.showToast({
			title: text,
			icon: success ? 'success' : 'none',
		});
	},
	isNullOrEmpty: function(value) {
		//是否为空
		return (value === null || value === '' || value === undefined) ? true : false;
	},
	trim: function(value) {
		//去空格
		return value.replace(/(^\s*)|(\s*$)/g, "");
	},
	isMobile: function(value) {
		//是否为手机号
		return /^(?:13\d|14\d|15\d|16\d|17\d|18\d|19\d)\d{5}(\d{3}|\*{3})$/.test(value);
	},
	isFloat: function(value) {
		//金额，只允许保留两位小数
		return /^([0-9]*[.]?[0-9])[0-9]{0,1}$/.test(value);
	},
	isNum: function(value) {
		//是否全为数字
		return /^[0-9]+$/.test(value);
	},
	checkPwd: function(value) {
		//密码为8~20位数字和字母组合
		return /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/.test(value);
	},
	formatNum: function(num) {
		//格式化手机号码
		if (utils.isMobile(num)) {
			num = num.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
		}
		return num;
	},
	rmoney: function(money) {
		//金额格式化
		return parseFloat(money).toFixed(2).toString().split('').reverse().join('').replace(/(\d{3})/g, '$1,').replace(
			/\,$/, '').split('').reverse().join('');
	},
	getYearMonthDay(nowDate) {
		const d = nowDate;
		const year = d.getFullYear();
		const month = d.getMonth() + 1 > 9 ? d.getMonth() + 1 : `0${d.getMonth() + 1}`;
		const date = d.getDate() > 9 ? d.getDate() : `0${d.getDate()}`;
		return `${year}-${month}-${date}`;
	},
	getFullDateTime(nowDate,type) {
		const d = nowDate;
		const year = d.getFullYear();
		const month = d.getMonth() + 1 > 9 ? d.getMonth() + 1 : `0${d.getMonth() + 1}`;
		const date = d.getDate() > 9 ? d.getDate() : `0${d.getDate()}`;
		const hour = d.getHours() > 9 ? d.getHours() : `0${d.getHours()}`;
		const minute = d.getMinutes() > 9 ? d.getMinutes() : `0${d.getMinutes()}`;
		const second = d.getSeconds() > 9 ? d.getSeconds() : `0${d.getSeconds() + 1}`;
		if(type == 'start') {
			return `${year}-${month}-${date} 00:00:00`;
		} else if(type == 'end') {
			return `${year}-${month}-${date} 23:59:59`;
		} else {
			return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
		}
	},
	formatDate: function(formatStr, fdate) {
		//日期格式化
		if (fdate) {
			if (~fdate.indexOf('.')) {
				fdate = fdate.substring(0, fdate.indexOf('.'));
			}
			fdate = fdate.toString().replace('T', ' ').replace(/\-/g, '/');
			var fTime, fStr = 'ymdhis';
			if (!formatStr)
				formatStr = "y-m-d h:i:s";
			if (fdate)
				fTime = new Date(fdate);
			else
				fTime = new Date();
			var month = fTime.getMonth() + 1;
			var day = fTime.getDate();
			var hours = fTime.getHours();
			var minu = fTime.getMinutes();
			var second = fTime.getSeconds();
			month = month < 10 ? '0' + month : month;
			day = day < 10 ? '0' + day : day;
			hours = hours < 10 ? ('0' + hours) : hours;
			minu = minu < 10 ? '0' + minu : minu;
			second = second < 10 ? '0' + second : second;
			var formatArr = [
				fTime.getFullYear().toString(),
				month.toString(),
				day.toString(),
				hours.toString(),
				minu.toString(),
				second.toString()
			]
			for (var i = 0; i < formatArr.length; i++) {
				formatStr = formatStr.replace(fStr.charAt(i), formatArr[i]);
			}
			return formatStr;
		} else {
			return "";
		}
	},
	/**
	 * 防抖
	 * @param {Function} 执行函数
	 * @param {Number} delay 延时ms   
	 */
	debounce: function(fn, delay = 500) {
		clearTimeout(_debounceTimeout);
		_debounceTimeout = setTimeout(() => {
			fn();
		}, delay);
	},
	/**
	 * 节流
	 * @param {Function} 执行函数
	 * @param {Number} delay 延时ms  
	 */
	throttle: function(fn, delay = 500) {
		if (_throttleRunning) {
			return;
		}
		_throttleRunning = true;
		fn();
		setTimeout(() => {
			_throttleRunning = false;
		}, delay);
	},
	/**
	 * 获取页面栈
	 * @param {Number} preIndex为1时获取上一页
	 * @return {Object} 
	 */
	prePage: function(preIndex = 1) {
		const pages = getCurrentPages();
		const prePage = pages[pages.length - (preIndex + 1)];

		return prePage.$vm;
	},
	// check登录状态及邀请人信息
	checkTokenAndInviterId(option) {
		uni.removeStorageSync('inviterId');
		// #ifdef MP-WEIXIN
		// 扫二维码打开的方式
		if (option.q) {
			uni.setStorageSync('inviterId', this.getUrlParam(decodeURIComponent(option.q), 'inviterId'));
		// 分享小程序入口方式
		} else if (option.inviterId) {
			uni.setStorageSync('inviterId', option.inviterId);
		}
		// #endif
		// #ifdef H5
		// 分享H5入口方式
		 uni.setStorageSync('inviterId', this.getUrlCode('inviterId'));
		// #endif
		// 没有token跳转登录页
		if(!this.getToken()) {
			// #ifdef H5
			uni.setStorageSync('loginSuccessUrl', window.location.href);
			// #endif
			uni.reLaunch({
				url: '/pages/home/login'
			})
			return false;
		// 如果有token 且有邀请人信息，更新
		} else if (uni.getStorageSync('inviterId')) {
			http.updateAuthorization({agencyId: uni.getStorageSync('inviterId')});
		}
		return true;
	},
	getUrlCode(name) {
		const code =  decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(window.location.href) || [, ''])[1]
			.replace(/\+/g, '%20')) || ''
		return code
	},
	gotoGoodsDetail(key, id) {
		// #ifdef H5
		if (wechat.isIOS()) {
			window.location.href = `/h5/packageA/pages/goodsDetails/goodsDetails?${key}=${id}&share=1`
		} else {
			uni.navigateTo({
				url: `/packageA/pages/goodsDetails/goodsDetails?${key}=${id}`
			})
		}
		// #endif
		// #ifndef H5
		uni.navigateTo({
			url: `/packageA/pages/goodsDetails/goodsDetails?${key}=${id}`
		})
		// #endif
	},
	getInviterId() {
		return uni.getStorageSync('inviterId');
	},
	getUrlParam(url, paraName) {
		let arrObj = url.split("?");
		if (arrObj.length > 1) {
			let arrPara = arrObj[1].split("&");
			let arr;
			for (let i = 0; i < arrPara.length; i++) {
				arr = arrPara[i].split("=");
				if (arr != null && arr[0] == paraName) {
					return arr[1];
				}
			}
			return "";
		} else {
			return "";
		}
	},
	/**
	 * toast
	 */
	msg: function(title = '', param = {}) {
		if (!title) return;
		uni.showToast({
			title,
			duration: param.duration || 1500,
			mask: param.mask || false,
			icon: param.icon || 'none'
		});
	},
	// 判断类型集合
	checkStr: function(str, type) {
		switch (type) {
			case 'mobile': //手机号码
				return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
			case 'tel': //座机
				return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str);
			case 'card': //身份证
				return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
			case 'mobileCode': //6位数字验证码
				return /^[0-9]{6}$/.test(str)
			case 'pwd': //密码以字母开头，长度在6~18之间，只能包含字母、数字
				return /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/.test(str)
				// return /^([a-zA-Z0-9]){8,18}$/.test(str)
			case 'payPwd': //支付密码 6位纯数字
				return /^[0-9]{6}$/.test(str)
			case 'postal': //邮政编码
				return /[1-9]\d{5}(?!\d)/.test(str);
			case 'QQ': //QQ号
				return /^[1-9][0-9]{4,9}$/.test(str);
			case 'email': //邮箱
				return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
			case 'money': //金额(小数点2位)
				return /^\d*(?:\.\d{0,2})?$/.test(str);
			case 'URL': //网址
				return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str)
			case 'IP': //IP
				return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str);
			case 'date': //日期时间
				return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) ||
					/^(\d{4})\-(\d{2})\-(\d{2})$/
					.test(str)
			case 'number': //数字
				return /^[0-9]+$/.test(str);
			case 'english': //英文
				return /^[a-zA-Z]+$/.test(str);
			case 'chinese': //中文
				return /^[\\u4E00-\\u9FA5]+$/.test(str);
			case 'lower': //小写
				return /^[a-z]+$/.test(str);
			case 'upper': //大写
				return /^[A-Z]+$/.test(str);
			case 'HTML': //HTML标记
				return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str);
			case 'withdraw': //提现金额
				return /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(str);
			default:
				return true;
		}
	},
	// 计算不同屏幕下屏幕元素真实宽高（用于热区、轮播图高度）
	calculateWidthAndHeight(value) {
		let windowWidth;
		uni.getSystemInfo({
			success(res) {
				windowWidth = res.windowWidth;
			}
		})
		// 以750作为基准 转为px
		const realVal = windowWidth * value / 750 + 'px';
		return realVal;
	},
	//计算点是否在一定范围内
	// pointInsideCircle(point, circle, r) {  
	//  if (r===0) return false  
	//  var dx = circle[0] - point[0]  
	//  var dy = circle[1] - point[1]  
	//  return dx * dx + dy * dy <= r * r;    
	// },
	//计算经纬度点距离
	pointInsideCircle(la1, lo1, la2, lo2) {
		var La1 = la1 * Math.PI / 180.0;  
		var La2 = la2 * Math.PI / 180.0;  
		var La3 = La1 - La2;  
		var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;  
		var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2)+Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));  
		s = s * 6378.137;//地球半径  
		s = Math.round(s * 10000) / 10000 * 1000;//m单位
		return s;
	},
	// 记录每天登录情况
	getRecordLogin() {
		let nowDate = new Date();
		console.log(nowDate)
		let oldDate=uni.getStorageSync('recordLoginTime');
		let flag=false;
		if(oldDate){
			flag=this.compareDate(nowDate,oldDate);
		}
		
		if(!oldDate||flag){
			let loginType=null;
			// #ifdef MP-WEIXIN
			loginType=1
			// #endif
			
			// #ifdef H5
			loginType=2
			// #endif
			
			// #ifdef APP-PLUS
			// 判断手机平台是 Android 还是 IOS
			let platform=uni.getSystemInfoSync().platform
			if (platform === 'android') {
				loginType=3
			} else if (platform === 'ios') {
				loginType=4
			}
			// #endif
			
			let param={
				loginType:loginType
			}
			http.recordLogin(param).then((res) => {
				if (res.status == 0) {
					uni.setStorageSync('recordLoginTime',nowDate);
				}
			})
		}
	},
	
	/**
	 * 判断日期1是否大于日期2，只到年月日
	 * @param {Object} date1
	 * @param {Object} date2
	 */
	compareDate(date1,date2){
	    var result = false;
	    if(date1.getFullYear()>date2.getFullYear()){
	        result = true;
	    }else if(date1.getFullYear() ==  date2.getFullYear()){
	          if(date1.getMonth() > date2.getMonth()){
	              result = true;
	          }else if(date1.getMonth() ==  date2.getMonth()){
	              if(date1.getDate() > date2.getDate()){
	                  result = true;
	              }
	          }
	    }
	    return result;
	}
}

export default utils;
